/*
 * @描述:  resize监听组件
 * @Author: /songzi
 * @Date: 2019-07-23 16:13:37
 * @Last Modified by: songzi
 * @Last Modified time: 2019-07-23 16:14:50
 */

import React, { Fragment, useEffect } from 'react';
import { debounce } from '@/utils/smallTool';

const Resize = props => {
  const { children, onRsize } = props;
  useEffect(() => {
    onRsize(document.body.clientWidth);
    const resizeDeb = debounce(onRsize, 500, true);
    window.addEventListener('resize', () => {
      resizeDeb(document.body.clientWidth);
    });
  });

  return <Fragment>{children}</Fragment>;
};
export default Resize;
